<template>
  <div>
    <el-cascader
      :value="departmentId"
      :options="options"
      clearable
      :props="{value:'id',label:'name'}"
      @change="handleChange"
    />
  </div>
</template>

<script>
// 导入接口
import { companyDepartmentRequest } from '@/api/department.js'
// 导入封装的递归函数
import { getsome } from '@/utils'
export default {
  props: {
    departmentId: {
      type: Number,
      required: true
    }
  },
  data() {
    return {
      // 部门联级选择器数据
      options: []
    }
  },
  created() {
    // 调用获取部门列表函数
    this.companyDepartment()
  },
  methods: {
    // 部门联级相关
    handleChange(value) {
      console.log(value)
      if (value.length > 0) {
        this.$emit('update:departmentId', value[value.length - 1])
      } else {
        this.$emit('update:departmentId', 1)
      }
    },
    // 封装发送获取部门列表函数
    async  companyDepartment() {
      const data = await companyDepartmentRequest()
      //  这是树状数据
      this.options = getsome(data.data, 0)
    }
  }
}
</script>

<style>

</style>
